﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Data;
using System.Diagnostics;

namespace document_manage.文件分类
{
    /// <summary>
    /// TXT.xaml 的交互逻辑
    /// </summary>
    public partial class TXT : Window
    {
        public TXT()
        {
            InitializeComponent();
            loadData();
        }

        MySQLConn con = new MySQLConn();            //连接数据库

        private void loadData()
        {
            dataGrid.Items.Clear();                 //先清空items才能绑定itemsource
            string sql = "select * from file where file_type = '.txt'";
            DataTable dt = new DataTable();         //新建DataTable类存放数据库输出结果
            dt = con.ExecuteQuery(sql);
            dataGrid.ItemsSource = dt.DefaultView;  //将datatable绑定到datagrid上
        }//end loadData

        //响应打开文件的事件
        private void Click1(object sender, RoutedEventArgs e)
        {
            //获取选中行的某列的值
            DataRowView selectedElement = (DataRowView)dataGrid.SelectedItem;
            string name = selectedElement.Row[1].ToString(); //获取第一列的值,即name值
            string path = selectedElement.Row[2].ToString();
            string s = (path + "\\" + name);
            Process.Start(s);
        }

        private void Click2(object sender, RoutedEventArgs e)
        {
            //获取选中行的某列的值
            DataRowView selectedElement = (DataRowView)dataGrid.SelectedItem;
            string path = selectedElement.Row[2].ToString();
            //打开文件夹
            Process.Start(path);
        }
    }
}
